var Rotation = 0.0;

main();

function main() {
    const canvas = document.querySelector('#canvas7');
    const gl = canvas.getContext('webgl');

    if (!gl) {
        alert('加载失败，请更换浏览器');
        return;
    }

    const dshaderProgramInfo = createDLightShaderProgramInfo(gl);
    const nshaderProgramInfo = createNormalShaderProgramInfo(gl);
    const s1shaderProgramInfo = createShadow1ProgramInfo(gl);
    const s2shaderProgramInfo = createShadow2ProgramInfo(gl);

    const cube_buffer = Cube_bufferInit(gl, 1.2);
    const fun_buffer = Fun_bufferInit(gl, fan_n=45, r=0.4);
    const square_buffer = Square_bufferInit(gl, r=0.15);
    const star_buffer = Star_bufferInit(gl, R = 0.2);
    const triangle_buffer = Triangle_bufferInit(gl, r = 0.2);
    const ball_buffer = Ball_bufferInit(gl, 1, 5);

    var then = 0;

    function render(now) {
        var packedInfos = [];

        const cubeLocation = [1.0, 1.0, -11.0];
        const ballLocation = [-1.0, 1.0, -8.0];

        //创建正方体

        cube_modelmatrixInfo = {
            translateAttri: cubeLocation,
            rotateSpeed: [1.0, 0.7, 0.8],
            // rotateSpeed: [0, 0, 0],
        };
        const cube_matrix = createModelViewMatrix(cube_modelmatrixInfo);

        const cube_packedInfo = packInfo(cube_buffer, cube_matrix, dshaderProgramInfo);
        packedInfos.push(cube_packedInfo);
        //////////

        //创建扇形

        fun_modelmatrixInfo = {
            translateAttri: cubeLocation,
            rotateSpeed: [1.8, 1.0, 2.0],
            transAfterRot: [0.0, 0.2, 0.0],
        };
        const fun_matrix = createModelViewMatrix(fun_modelmatrixInfo);

        const fun_packedInfo = packInfo(fun_buffer, fun_matrix, nshaderProgramInfo);
        packedInfos.push(fun_packedInfo);
        //////////

        //创建正方形

        square_modelmatrixInfo = {
            translateAttri: cubeLocation,
            rotateSpeed: [0.8, 2.0, 1.6],
            transAfterRot: [0.0, 0.6, 0.0],
        };
        const square_matrix = createModelViewMatrix(square_modelmatrixInfo);

        const square_packedInfo = packInfo(square_buffer, square_matrix, nshaderProgramInfo);
        packedInfos.push(square_packedInfo);
        //////////

        //创建五角星

        star_modelmatrixInfo = {
            translateAttri: cubeLocation,
            rotateSpeed: [2.0, 1.2, 1.8],
            transAfterRot: [0.0, -0.2, 0.0],
        };
        const star_matrix = createModelViewMatrix(star_modelmatrixInfo);

        const star_packedInfo = packInfo(star_buffer, star_matrix, nshaderProgramInfo);
        packedInfos.push(star_packedInfo);
        //////////

        //创建三角形

        triangle_modelmatrixInfo = {
            translateAttri: cubeLocation,
            rotateSpeed: [1.4, 1.4, 1.4],
            transAfterRot: [0.0, -0.6, 0.0],
        };
        const triangle_matrix = createModelViewMatrix(triangle_modelmatrixInfo);

        const triangle_packedInfo = packInfo(triangle_buffer, triangle_matrix, nshaderProgramInfo);
        packedInfos.push(triangle_packedInfo);
        //////////

        //创建球体
        ball_modelmatrixInfo = {
            translateAttri: ballLocation,
            rotateSpeed: [0.7, 0.8, 1.0],
            transAfterRot: [0.0, 0.3, 0.0],
        };
        const ball_matrix = createModelViewMatrix(ball_modelmatrixInfo);

        const ball_packedInfo = packInfo(ball_buffer, ball_matrix, dshaderProgramInfo);
        const ballshade1_packedInfo = packInfo(ball_buffer, ball_matrix, s1shaderProgramInfo);
        const ballshade2_packedInfo = packInfo(ball_buffer, ball_matrix, s2shaderProgramInfo);
        packedInfos.push(ball_packedInfo);
        packedInfos.push(ballshade1_packedInfo);
        packedInfos.push(ballshade2_packedInfo);
        //////////

        now *= 0.001;
        const deltaTime = now - then;
        then = now;

        drawScene(gl, packedInfos, deltaTime);

        requestAnimationFrame(render);
    }

    requestAnimationFrame(render);
}